//
//  DateUtil.m
//  LOU
//
//  Created by iMacOne on 15/11/11.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "DateUtil.h"

@implementation DateUtil
#pragma mark 一串数字格式的String
+ (NSString*)formatDateNoStr:(NSDate*)date {
    return (nil != date ? [[DateUtil formatDateNo] stringFromDate:date] : @"");
}
#pragma mark 一串数字格式的Format
+ (NSDateFormatter*)formatDateNo {
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:DATE_NO_FORMAT];
    return format;
}
#pragma mark 日期时间格式的String
+ (NSString*)formatDateTimeStr:(NSDate*)date
{
    return (nil != date ? [[DateUtil formatDateTime] stringFromDate:date] : @"");
    return nil;
    
}
#pragma mark 日期时间格式的Format
+ (NSDateFormatter*)formatDateTime
{
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:DATE_TIME_FORMAT];
    return format;

}

+(NSString *)toFormatDateDate:(NSDate *)date{
    NSTimeInterval currentTimestamp = [[NSDate date] timeIntervalSince1970];
    NSTimeInterval timestamp = [date timeIntervalSince1970];
    NSTimeInterval poor = currentTimestamp - timestamp;//秒数
    if (poor < 60) {
        return @"刚刚";
    } else if (poor < 60*60) {
        //小于1小时
        return [NSString stringWithFormat:@"%i分钟前",(int)(poor / 60)];
    } else if (poor < 60*60*24) {
        //小于1天
        return [NSString stringWithFormat:@"%i小时前",(int)(poor / (60*60))];
    } else if (poor < 60*60*24*7) {
        //小于一周
        return [NSString stringWithFormat:@"%i天前",(int)(poor / (60*60*24))];
    }
    //    else if (poor < 60*60*24*30*12){
    //
    //        return [NSString stringWithFormat:@"%i月前",(int)(poor/(60*60*24*30))];
    //    }
    else {
        //    } else if (poor < 60*60*24*30*12) {
        //        return [NSString stringWithFormat:@"%i月前",(int)(poor / (60*60*24*30))];
        //    } else {
        //        return [NSString stringWithFormat:@"%i年前",(int)(poor / (60*60*24*30*12))];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd"];
        
        
        return [formatter stringFromDate:date];
        
    }
}

@end
